Last updated: 2023-07-31

Checks: 5 1

Knit directory: WenjunLiu_Thesis_Chapter4/

This reproducible R Markdown analysis was created with workflowr (version 1.7.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20200930) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Tracking code development and connecting the code version to the results is critical for reproducibility. To start using Git, open the Terminal and type git init in your project directory.


This project is not being versioned with Git. To obtain the full reproducibility benefits of using workflowr, please see ?wflow_start.


library(ngsReports)
library(tidyverse)
library(yaml)
library(scales)
library(pander)
library(glue)
library(plotly)
panderOptions("table.split.table", Inf)
panderOptions("big.mark", ",")
theme_set(theme_bw())
config <- here::here("config/config.yml") %>%
  read_yaml()
suffix <- paste0(config$tag, config$ext)
sp <- config$ref$species %>%
  str_replace("(^[a-z])[a-z]*_([a-z]+)", "\\1\\2") %>%
  str_to_title()
samples <- config$samples %>%
  here::here() %>%
  read_tsv() %>%
  mutate(
    Filename = paste0(sample, suffix)
  )
config$analysis <- config$analysis %>%
  lapply(intersect, y = colnames(samples)) %>%
  .[vapply(., length, integer(1)) > 0]
if (length(config$analysis)) {
  samples <- samples %>%
    unite(
      col = group, 
      any_of(as.character(unlist(config$analysis))), 
      sep = "_", remove = FALSE
    )
} else {
  samples$group <- samples$Filename
}
group_cols <- hcl.colors(
  n = length(unique(samples$group)), 
  palette = "Zissou 1"
  ) %>%
  setNames(unique(samples$group))

Quality Assessment on Raw Data

rawFqc <- here::here("data/raw/FastQC") %>%
  list.files(pattern = "zip", full.names = TRUE) %>%
  FastqcDataList() %>%
  .[fqName(.) %in% samples$Filename]
plotSummary(rawFqc) +
  theme(axis.text.y=element_blank()) 
*Overall summary of FastQC reports*

Overall summary of FastQC reports

Library Sizes

A total of 792 libraries were contained in this dataset, with read totals ranging between 974,545 and 6,174,727 reads.

Across all libraries, reads were 40 bases.

plotReadTotals(rawFqc, pattern = suffix) +
  theme(axis.text.y=element_blank())
*Library Sizes for all supplied fastq files. Any samples run as multiple libraries are  shown as the supplied multiple libraries and have not been merged.*

Library Sizes for all supplied fastq files. Any samples run as multiple libraries are shown as the supplied multiple libraries and have not been merged.

Sequence Quality

plotBaseQuals(
  rawFqc,
  pattern = suffix, 
  dendrogram = TRUE,
  cluster = TRUE
  ) +
  theme(axis.text.y=element_blank())
*Mean sequencing quality scores at each base position for each library*

Mean sequencing quality scores at each base position for each library

GC Content

plotGcContent(
  x = rawFqc, 
  pattern = suffix, 
  species = sp, 
  gcType = "Trans",
  usePlotly = TRUE,
  dendrogram = TRUE,
  cluster = TRUE
  )

GC content shown as the % above and below the theoretical GC content for the Hsapiens transcriptome.

ggplotly(
  getModule(rawFqc, "Per_sequence_GC_content") %>%
    group_by(Filename) %>%
    mutate(
      cumulative = cumsum(Count) / sum(Count)
    ) %>%
    ungroup() %>%
    left_join(samples) %>%
    bind_rows(
      getGC(gcTheoretical, sp, "Trans") %>%
        mutate_at(sp, cumsum) %>% 
        rename_all(
          str_replace_all, 
          pattern = sp, replacement = "cumulative",
        ) %>%
        mutate(
          Filename = "Theoretical GC",
          group = Filename
        )
    ) %>%
    mutate(
      group = as.factor(group),
      group = relevel(group, ref = "Theoretical GC"),
      cumulative = round(cumulative*100, 2)
    ) %>%
    ggplot(aes(GC_Content, cumulative, group = Filename)) +
    geom_line(aes(colour = group), size = 1/3) +
    scale_x_continuous(label = ngsReports:::.addPercent) +
    scale_y_continuous(label = ngsReports:::.addPercent) +
    scale_colour_manual(
      values = c("#000000", group_cols)
    ) +
    labs(
      x = "GC Content",
      y = "Cumulative Total",
      colour = "Group"
    )
)

GC content shown as a cumulative distribution for all libraries. Groups can be hidden by clicking on them in the legend.

Sequence Content

plotly::ggplotly(
  getModule(rawFqc, module = "Per_base_sequence_content") %>% 
    mutate(Base = fct_inorder(Base)) %>%
    group_by(Base) %>% 
    mutate(
      across(c("A", "C", "G", "T"), function(x){x - mean(x)}) 
    ) %>% 
    pivot_longer(
      cols = c("A", "C", "G", "T"), 
      names_to = "Nuc", 
      values_to = "resid"
    ) %>%
    left_join(samples) %>%
    ggplot(
      aes(Base, resid, group = Filename, colour = group)
    ) + 
    geom_line() +
    facet_wrap(~Nuc) + 
    scale_colour_manual(values = group_cols) +
    labs(
      x = "Read Position", y = "Residual", colour = "Group"
    )
)

Base and Position specific residuals for each sample. The mean base content at each position was calculated for each nucleotide, and the sample-specific residuals calculated.

AdapterContent

plotAdapterContent(
  x = rawFqc, 
  pattern = suffix, 
  dendrogram = TRUE,
  usePlotly = TRUE, 
  cluster = TRUE
  ) 

Total Adapter Content for each sample shown by starting position in the read.

Overrepresented Sequences

os <- suppressMessages(getModule(rawFqc, "Over"))
if (nrow(os)){
  if (length(unique(os$Filename)) > 1){
    suppressMessages(
      plotOverrep(
        x = rawFqc,
        pattern = suffix, 
        usePlotly = TRUE,
        dendrogram = TRUE,
        cluster = TRUE
      )
    )
  }
}

Summary of over-represented sequences across all libraries

os %>%
  group_by(Sequence, Possible_Source) %>%
  summarise(
    `Found in` = n(),
    Total = sum(Count),
    `Largest Percent` = glue("{round(max(Percentage), 2)}%")
  ) %>%
  pander(
    caption = "*Summary of over-represented sequences within the raw data.*"
  )
Summary of over-represented sequences within the raw data.
Sequence Possible_Source Found in Total Largest Percent
GATCGGAAGAGCACACGTCTGAACTCCAGTCACCGGCTAT TruSeq Adapter, Index 7 (97% over 36bp) 24 82,796 0.4%
GATCGGAAGAGCACACGTCTGAACTCCAGTCACCTGAAGC TruSeq Adapter, Index 19 (97% over 38bp) 13 46,538 0.17%
GATCGGAAGAGCACACGTCTGAACTCCAGTCACGAATTCG TruSeq Adapter, Index 7 (97% over 35bp) 8 32,012 0.19%
GATCGGAAGAGCACACGTCTGAACTCCAGTCACGAGATTC TruSeq Adapter, Index 7 (97% over 38bp) 20 115,699 0.45%
GATCGGAAGAGCACACGTCTGAACTCCAGTCACTAATGCG TruSeq Adapter, Index 3 (97% over 36bp) 8 44,747 0.39%
GATCGGAAGAGCACACGTCTGAACTCCAGTCACTCCGCGA TruSeq Adapter, Index 6 (97% over 36bp) 16 60,076 0.26%
GATCGGAAGAGCACACGTCTGAACTCCAGTCACTCCGGAG TruSeq Adapter, Index 6 (97% over 36bp) 16 82,428 0.51%
GATCGGAAGAGCACACGTCTGAACTCCAGTCACTCTCGCG TruSeq Adapter, Index 8 (97% over 36bp) 8 30,101 0.19%

sessionInfo()
R version 4.3.0 (2023-04-21)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.3.1

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRblas.0.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Australia/Adelaide
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] plotly_4.10.2       glue_1.6.2          pander_0.6.5       
 [4] scales_1.2.1        yaml_2.3.7          lubridate_1.9.2    
 [7] forcats_1.0.0       stringr_1.5.0       dplyr_1.1.2        
[10] purrr_1.0.1         readr_2.1.4         tidyr_1.3.0        
[13] tidyverse_2.0.0     ngsReports_2.2.4    tibble_3.2.1       
[16] patchwork_1.1.2     ggplot2_3.4.2       BiocGenerics_0.46.0

loaded via a namespace (and not attached):
 [1] tidyselect_1.2.0        viridisLite_0.4.2       farver_2.1.1           
 [4] Biostrings_2.68.1       bitops_1.0-7            fastmap_1.1.1          
 [7] lazyeval_0.2.2          RCurl_1.98-1.12         promises_1.2.0.1       
[10] digest_0.6.33           timechange_0.2.0        lifecycle_1.0.3        
[13] ellipsis_0.3.2          magrittr_2.0.3          compiler_4.3.0         
[16] rlang_1.1.1             sass_0.4.6              tools_4.3.0            
[19] utf8_1.2.3              data.table_1.14.8       knitr_1.43             
[22] labeling_0.4.2          htmlwidgets_1.6.2       bit_4.0.5              
[25] here_1.0.1              RColorBrewer_1.1-3      plyr_1.8.8             
[28] workflowr_1.7.0         withr_2.5.0             grid_4.3.0             
[31] stats4_4.3.0            fansi_1.0.4             git2r_0.32.0           
[34] colorspace_2.1-0        MASS_7.3-60             cli_3.6.1              
[37] rmarkdown_2.23          crayon_1.5.2            generics_0.1.3         
[40] rstudioapi_0.15.0       httr_1.4.6              reshape2_1.4.4         
[43] tzdb_0.4.0              cachem_1.0.8            zlibbioc_1.46.0        
[46] parallel_4.3.0          XVector_0.40.0          vctrs_0.6.3            
[49] jsonlite_1.8.7          IRanges_2.34.1          hms_1.1.3              
[52] S4Vectors_0.38.1        bit64_4.0.5             crosstalk_1.2.0        
[55] jquerylib_0.1.4         ggdendro_0.1.23         DT_0.28                
[58] stringi_1.7.12          gtable_0.3.3            later_1.3.1            
[61] GenomeInfoDb_1.36.1     munsell_0.5.0           pillar_1.9.0           
[64] htmltools_0.5.5         GenomeInfoDbData_1.2.10 R6_2.5.1               
[67] rprojroot_2.0.3         vroom_1.6.3             evaluate_0.21          
[70] lattice_0.21-8          highr_0.10              httpuv_1.6.11          
[73] bslib_0.5.0             Rcpp_1.0.11             xfun_0.39              
[76] fs_1.6.2                zoo_1.8-12              pkgconfig_2.0.3